<?php
namespace app\admin\model;

use think\Model;
                    

class SaasGoods extends Model
{
    public function getPageAll($where){

        $rs = SaasGoods::where($where)
            ->order('sort desc')
            ->order('id desc')
            ->paginate(20);

        return $rs;

    }

    public function getAll($where){
                    
        $rs = SaasGoods::where($where)
                    
        ->select();
                    
        return $rs;
                    
    }

    public function getHot($where){

        $rs = SaasGoods::where($where)

            ->order('sort desc')

            ->limit(27)

            ->select();

        return $rs;
    }
                    
    public function getOne($where){
                    
        $rs = SaasGoods::where($where)
                    
        ->find();
                    
        return $rs;

    }

    public function getOneMore($where){

        $rs = SaasGoods::alias('sg')

            ->where('sg.id','=',$where['id'])

            ->join('saas_business sb','sg.b_id = sb.id','LEFT')

            ->field('sg.*,sb.name as business_name')

            ->find();

        return $rs;

    }
                    
    public function add($data){
                    
        $rs = SaasGoods::data($data)
                    
        ->save();
                    
        return $rs;
                    
    }
                    
    public function edit($where,$data){
                    
        $rs = SaasGoods::where($where)
                    
        ->update($data);
                    
        return $rs;
                    
    }
                    
    public function del($where){
                    
        $rs = SaasGoods::where($where)
                    
        ->delete();
                    
        return $rs;
                    
    }

    public function totalNum(){
        $rs = SaasGoods::where('status',1)
            ->count('id');
        return $rs;
    }

    public function totalNumWhere($where){
        $rs = SaasGoods::where($where)
            ->count('id');
        return $rs;
    }
}
                    
